/*
 * @Description: 科目父类Hook
 * @Date: 2022-12-16 13:30:40
 * @Author: lizhiqiang
 */
import { GOP } from "@/request/integralaccounttitle"
import { useEffect, useState } from "react"

export default function useAccountTitleParents () {
    const [ accountTitleParentOptions, setAccountTitleParentOptions ] = useState<Array<Record<string,unknown>>>([])
    const getData = async () => {
        const { code, data } = await GOP()
        if ( code === 200 ) {
            setAccountTitleParentOptions(data.map((item: { accountTitleName: any; pkAccountTitle: any })=>{
                return {
                    label: item.accountTitleName,
                    value: item.pkAccountTitle
                }
            }))
        } else {
            setAccountTitleParentOptions( [] )
        }
    }
    useEffect( () => {
        getData()
    }, [] )
    return accountTitleParentOptions
}